/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Objekte;

import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
import logging.Logger;

/**
 * Für die anzeige im inventar des Users
 * @author benji
 *
 */
public class ProduktListModel extends AbstractTableModel {
    private String[] columns = new String[] {"ID", "Name"};
    private ArrayList<Produkt> data = new ArrayList<Produkt>();

    public void setData(ArrayList<Produkt> data){
        this.data = data;
        fireTableDataChanged();
        Logger.debug("Füle Inventarliste");
    }

    public void addProdukt(Produkt p){
        data.add(p);
        fireTableRowsInserted(data.size(), data.size());
        Logger.debug("Füge Product hinzu");
    }

    public Produkt getRow(int i) {
        return data.get(i);
    }

    @Override
    public int getRowCount() {
        return this.data.size();
    }

    @Override
    public int getColumnCount() {
        return this.columns.length;
    }

    @Override
    public String getColumnName(int i){
        return this.columns[i];
    }

    @Override
    public Object getValueAt(int row, int column) {
        Produkt p = data.get(row);
        switch(column){
            case 0: return p.getID();
            case 1: return p.getName();
            default: return null;
        }
    }

    @Override
    public Class getColumnClass(int i){
        switch(i){
            case 0: return Integer.class;
            case 1: return String.class;
            default: return null;
        }
    }

    @Override
    public void setValueAt(Object value, int row, int col) {
    }
}
